<template>
	<view class="flex align-center justify-center flex-direction">
		<view class="list flex align-center">
			<text>原始密码</text>
			<input placeholder="原始密码" v-model="oldPassword"/>
		</view>
		<view class="list flex align-center">
			<text>新密码</text>
			<input placeholder="新密码" v-model="password"/>
		</view>
		<view class="list flex align-center">
			<text>确认密码</text>
			<input placeholder="确认密码" v-model="conPassword"/>
		</view>
		<view class="flex align-center justify-center">
			<view class="btn" @tap="loadUser">确认</view>
		</view>
	</view>
</template>

<script>
	var api = require('@/components/api.js');
	export default {
		data() {
			return {
				loading: false,
				oldPassword: '',
				password: '',
				conPassword:'',
			}
		},
		onLoad(){
			
		},
		methods: {
			loadUser: function() {
				try {
					if (this.password == '' || this.oldPassword == '' ||this.conPassword == '') {
						uni.showToast({
							icon: 'none',
							title: '请输入密码'
						});
						this.loading = false;
						return;
					}
					if(!(this.password==this.conPassword)){
						uni.showToast({
							icon: 'none',
							title: '输入密码不一致，请输入密码'
						});
						this.loading = false;
						return;
					}
					if(this.password==this.oldPassword){
						uni.showToast({
							icon: 'none',
							title: '新旧密码一样，请重新设置新密码'
						});
						this.loading = false;
						return;
					}
					var userId = uni.getStorageSync('user').user_id;
					api.get({
						url: 'User/GetPwdEdit',
						data: {
							user_id: userId,
							password_old:this.oldPassword,
							password:this.password
						},
						success: data => {
							if (data.ErrCode == 0) {
								uni.showToast({
									title:'修改成功'
								})
								this.loading = false;
								uni.setStorageSync('user','')
								uni.navigateTo({
									url: '/pages/login/login'
								})
								return;
							}
						}
					});
				} catch (e) {
					console.log(e)
					uni.showModal({
						title: '提示',
						content: '账号超时，请重新登陆',
						success: (res) => {
							if (res.confirm) {
								uni.navigateTo({
									url: '/pages/login/login'
								});
							}
						}
					});
				}
			},
			
		}
	}
</script>

<style lang="scss" scoped>
	.btn{
		text-align: center;
		width: 560upx;
		line-height: 70upx;
			height: 70upx;
			background-color: $btn-bground;
			border-radius: 35upx;
			color: #fff;
			font-size: 28upx;
			margin-top: 36upx;
	}
	.list>input{
		font-size: 30upx;
		width: 500upx;
		margin-left: 60upx;
	}
	.list>text{
		width: 120upx;
			font-size: 30upx;
			color: #000000;
			
	}
	.list{
		margin-top: 20upx;
		width: 100%;
		padding-left: 36upx;
		height: 92upx;
		background-color: #ffffff;
		border: solid 1upx #d7d7d7;
	}
</style>
